package org.bonorsoft.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.bonorsoft.common.constant.CacheConstant;
import org.bonorsoft.modules.system.entity.SysDictItem;
import org.bonorsoft.modules.system.mapper.SysDictItemMapper;
import org.bonorsoft.modules.system.service.ISysDictItemService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 对应字典类别下的字典值
 * @Author: WilliamYe
 * @Date:   2020-11-18
 * @Version: V1.0
 */
@Service
@Slf4j
public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDictItem> implements ISysDictItemService {

    @Resource
    private SysDictItemMapper sysDictItemMapper;

    @Override
    public String selectDictLabel(String dictType, String dictValue) {
        QueryWrapper<SysDictItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dict_id", dictType).eq("item_value",dictValue);
        SysDictItem sysDictItem = sysDictItemMapper.selectOne(queryWrapper);
        return sysDictItem.getItemText();
    }

    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    @Cacheable(value = CacheConstant.SYS_DICT_CACHE_ITME,key = "#dictType")
    public List<SysDictItem> selectDictDataByType(String dictType) {
        log.info("无缓存dictItem的时候调用这里！");
        return sysDictItemMapper.selectDictDataByType(dictType);
    }

    @Override
    public String getValueByTableAndKey(String table, String key) {
        return sysDictItemMapper.getValueByTableAndKey(table,key);
    }
}
